<template>
    <view class="xilu">
        <view class="container p30">
            <!-- <view class="fs34 col10 pb30">圈子管理员</view>
            <view class="flex-box pb40">
                <image src="../../static/images/goods.png" mode="aspectFill" class="xilu_avatar"></image>
                <view class="flex-grow-1">
                    <view class="fs32 blue pb20">西瓜味的棉花糖</view>
                    <view class="fs24 col5">粉丝数：128</view>
                </view>
                <view class="btn1">+ 关注</view>
            </view> -->

            <view class="fs34 col10 pb30">全部圈友·{{total}}名</view>
			<mescroll-body ref="mescrollRef" :fixed="false" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
				<view class="flex-box pb40" v-for="(item,index) in userList" @click="bindHome(item.user_id)">
					<image :src="item.user.avatar" mode="aspectFill" class="xilu_avatar"></image>
					<view class="flex-grow-1">
						<view class="fs32 blue pb20">{{item.user.nickname}}</view>
						<view class="fs24 col5">粉丝数：{{item.fans_count}}</view>
					</view>
					<view class="btn1" @click="toggleFocus(index)" v-if="!item.is_focus_count">+ 关注</view>
					<view class="btn1" @click="toggleFocus(index)" v-else>已关注</view>
				</view>
			</mescroll-body>
        </view>
    </view>
</template>

<script>
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
    export default {
		 mixins: [MescrollMixin], // 使用mixin
        data() {
            return {
				total: 0,
				topicId:0,
				upOption:{
					auto: false
				},
				downOption: {
				    autoShowLoading: true, // 显示下拉刷新的进度条
				    textColor: "#aaa" ,// 下拉刷新的文本颜色
					auto: false
				},
				userList:[]
            };
        },
		onLoad(options) {
			this.topicId = options.topic_id;
			this.mescroll.resetUpScroll();
		},
		methods:{
			/*上拉加载的回调*/
			upCallback(page) {
				// 此处可以继续请求其他接口
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				this.$core.get({
					url: 'xilumarket.topic/topic_users',
					loading:false,
					data:{topic_id: this.topicId,page: pageNum,pageSize:pageSize},
					success: (ret) => {
						let data = ret.data;
						// 接口返回的当前页数据列表 (数组)
						let curPageData = data.data;
						// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
						let curPageLen = curPageData.length;
						// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
						let totalPage = data.last_page;
						// 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
						//let totalSize = data.total;
						// 接口返回的是否有下一页 (true/false)
						//let hasNext = data.current_page;
				
						//设置列表数据
						if (page.num == 1) this.userList = []; //如果是第一页需手动置空列表
						this.userList = this.userList.concat(curPageData); //追加新数据
						this.total = data.total;
						// 请求成功,隐藏加载状态
						//方法一(推荐): 后台接口有返回列表的总页数 totalPage
						this.mescroll.endByPage(curPageLen, totalPage);
				
						
						setTimeout(() => {
							this.mescroll.endSuccess(curPageLen)
						}, 20)
					},
					fail: () => {
						//  请求失败,隐藏加载状态
						this.mescroll.endErr()
					}
				})
			},
			bindHome(userId){
				uni.navigateTo({
					url: '/pages/home_page/home_page?id='+userId+'&tab=forum'
				})
			},
			// 关注取关
			toggleFocus(index) {
				if(!this.$core.getUserinfo(true)){
					return true;
				}
				this.$core.post({url: 'xilumarket.forum/toggle_focus',data: {user_id: this.userList[index].user_id},success: ret => {
						this.userList[index].is_focus_count = ret.data.is_focus_count;
						this.$forceUpdate();
					},fail: err => {
						console.log(err);
					}
				});
			},
		}
    }
</script>

<style lang="scss" scoped>
    .xilu {
        &_avatar {
            width: 100rpx;
            height: 100rpx;
            border-radius: 50%;
            margin-right: 30rpx;
        }

        .btn1 {
            width: 110rpx;
            height: 56rpx;
            line-height: 56rpx;
            font-size: 24rpx;
        }
    }
</style>
